<?php

header("Content-Type: application/json charset=UTF-8");

$connect = mysqli_connect('localhost','root','root','22mysql');
if (!$connect) {
    echo json_encode(['code' => 0, 'msg' => '数据库连接失败']);
}
$sql = "select bm.name,count(*) as total from yg join bm on yg.dept_id = bm.id GROUP BY dept_id";

$query = mysqli_query($connect,$sql);
$data = mysqli_fetch_all($query,MYSQLI_ASSOC);


$xData = [];
$yData = [];
foreach ($data as $val) {
    $xData[] = $val['name'];
    $yData[] = $val['total'];
}

echo json_encode(['code' => 1, 'msg' => '查询成功', 'data' =>[
    'x' => $xData,
    'y' => $yData,
]]);
